<template>
	<view class="withdraw l-whitespace">
		<view class="withdraw-ewm">
			<view class="withdraw-ewm-r">
				<van-cell-group>
				  <van-field
					:value="scanCode"
					clearable
					placeholder="请输入钱包地址"
					:border="false"
					@change="onChange"
				  >
				  	<view 
					@click="onScanCode"
						slot="left-icon"
						class="icon-btn iconfont icon-sao">
				  	</view>
				  </van-field>
				</van-cell-group>
			</view>
		</view>
		<view class="integral">
			<van-cell-group class="integral-bg">
			  <van-field
				clearable
				:value="integral"
				type="number"
				input-class="integral-input"
				placeholder="请输入WNCT数量"
				@clear="onClear"
				@change="onChange"
			  />
			</van-cell-group>
			<view class="integral-info">
				<text class="integral-info-txt">实际转出：{{integral}}</text>
			</view>
			<view class="integral-info">
				<text class="integral-info-txt color-black">WNCT余额 {{balances}}</text>
				<text class="integral-info-btn" @click="onWNCTAllTransfer">全部转账</text>
			</view>
			<view class="integral-info">
				<text class="integral-info-txt">手续费</text>
				<text class="integral-info-txt">1%-5%({{charge}}WNCT)</text>
			</view>
			<view class="slider">
				<text>慢</text>
				<view class="slider-wrap">
					<van-slider @change="sliderChange"
					 use-button-slot
					 :value="sliderValue" step="20" min="20" >
					 <view class="custom-button" slot="button">
						 {{sliderValue / 20}}%
					 </view>
					 </van-slider>
				</view>
				<text>快</text>
			</view>
		</view>
		<view class="paly-btn">
			<van-button square type="primary" size="large" custom-class="paly-btn-bg">提币</van-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				scanCode: '',
				charge: 0,
				integral: 0,
				balances: 50,
				sliderValue: 20
			}
		},
		onLoad() {

		},
		methods: {
			onScanCode () {
				uni.scanCode({
					onlyFromCamera: true,
					success: (res) => {
						this.scanCode = res.result
					}
				});
			},
			onChange (e) {
				const data = e.detail
				if (data >= this.balances * ((this.sliderValue / 20) / 100 )) {
					this.onWNCTAllTransfer()
					return false
				}
				this.integral = parseInt(data)
				this.charge = this.integral * ((this.sliderValue / 20) / 100 )
			},
			onClick () {
			},
			onClear () {
				this.integral = 0
				this.charge = 0
			},
			onWNCTAllTransfer () {
				this.integral = this.balances * (1 - (this.sliderValue / 20) / 100 )
				this.charge = this.balances * ((this.sliderValue / 20) / 100 )
			},
			sliderChange (e) {
				console.log(e)
				this.sliderValue = e.detail
				this.onWNCTAllTransfer()
			}
		},
	}
</script>

<style scoped lang="scss">
	@import '../../../common/trade.scss';
	.custom-button {
		width:25px;
		height:25px;
		line-height: 25px;
		font-size: 22upx;
		color: #1989fa;
		text-align: center;
		border-radius:50%;
		background-color:#fff;
		box-shadow:0 1px 2px rgba(0,0,0,.5);
	}
</style>
